import { useState, useEffect } from "react";

// 通用的仪表板数据Hook
export const useDashboardData = () => {
  // 当前时间状态
  const [currentTime, setCurrentTime] = useState<string>(
    new Date().toLocaleTimeString("zh-CN", { hour12: false })
  );

  // 时间范围状态
  const [timeRange, setTimeRange] = useState<"week" | "month">("week");

  // 更新时间效果
  useEffect(() => {
    const timer = setInterval(() => {
      setCurrentTime(new Date().toLocaleTimeString("zh-CN", { hour12: false }));
    }, 1000);
    return () => clearInterval(timer);
  }, []);

  return {
    currentTime,
    timeRange,
    setTimeRange,
  };
};
